package cn.edu.szu.bigdata.secure;

import com.qihoo.wzws.rzb.routine.RoutineReportCache;
import com.qihoo.wzws.rzb.routine.po.CommonStatBean;
import com.qihoo.wzws.rzb.routine.po.CommonStatBeanComparator;
import com.qihoo.wzws.rzb.routine.po.SearchKeyWordBean;
import com.qihoo.wzws.rzb.routine.po.SearchKeyWordComparator;
import com.qihoo.wzws.rzb.routine.po.StatBean;
import com.qihoo.wzws.rzb.routine.po.StatBeanComparator;
import com.qihoo.wzws.rzb.secure.po.AttackEntity;
import com.qihoo.wzws.rzb.secure.po.CCEntity;
import com.qihoo.wzws.rzb.secure.po.CommBean;
import com.qihoo.wzws.rzb.util.DateUtil;
import com.qihoo.wzws.rzb.util.Utils;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;

public class ReportOutput {
    public static File file = null;

    public ReportOutput() {
    }

    public static void outputAttackHtml() {
        try {
            if (AttackReportCache.startTime == null) {
                return;
            }

            Properties properties = new Properties();
            properties.setProperty("ISO-8859-1", "UTF-8");
            properties.setProperty("input.encoding", "UTF-8");
            properties.setProperty("output.encoding", "UTF-8");
            if (AnalyzeSingle.isJarExecute) {
                properties.setProperty("resource.loader", "jar");
                properties.setProperty("jar.resource.loader.class", "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
                properties.setProperty("jar.resource.loader.path", "jar:file:" + AnalyzeSingle.jarPath);
            } else {
                properties.setProperty("resource.loader", "class");
                properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
                properties.setProperty("class.resource.loader.path", AnalyzeSingle.basePath);
            }

            VelocityEngine velocityEngine = new VelocityEngine(properties);
            Template template = velocityEngine.getTemplate("template/security-data.html", "UTF-8");
            VelocityContext context = new VelocityContext();
            NumberFormat performat = NumberFormat.getPercentInstance();
            performat.setMinimumFractionDigits(3);
            NumberFormat intformat = NumberFormat.getNumberInstance();
            intformat.setMaximumFractionDigits(0);
            NumberFormat decimalformat = NumberFormat.getNumberInstance();
            decimalformat.setRoundingMode(RoundingMode.HALF_UP);
            decimalformat.setMaximumFractionDigits(2);
            AttackReportCache.initData();
            int attackCounts = AttackReportCache.attackCount.intValue();
            String ccCounts;
            String cc_ip;
            if (AnalyzeSingle.useCC) {
                ccCounts = intformat.format(AttackReportCache.ccCount);
                cc_ip = intformat.format(AttackReportCache.ccIPList.size());
            } else {
                ccCounts = "-";
                cc_ip = "-";
            }

            int attackTypeSum = AttackReportCache.getattackTypeSum();
            int visits = RoutineReportCache.visits;
            int UIP = AttackReportCache.attackIPList.size() + AttackReportCache.ccIPList.size();
            String fromDate;
            if (AttackReportCache.dataFrom.size() > 1) {
                fromDate = DateUtil.formatDate(RoutineReportCache.dataFrom.get(0)) + "至" + DateUtil.formatDate(RoutineReportCache.dataFrom.get(RoutineReportCache.dataFrom.size() - 1));
            } else {
                fromDate = DateUtil.formatDate(RoutineReportCache.dataFrom.get(0));
            }

            String attackDatajson = AttackReportCache.ForAttackDatajson();
            String allDaysDetailsjson = AttackReportCache.ForallDaysDetailsjson();
            String attackVObjectjson = AttackReportCache.ForattackVObjectjson();
            List<CommBean> attackCountryRegionList = AttackReportCache.GetAttackCountryRegionList(intformat);
            List<StatBean> attackIPRegionList = AttackReportCache.GetAttackIPRegionList(intformat, performat);
            List<StatBean> ccIPRegionList = AttackReportCache.GetCcIPRegionList(intformat, performat);
            Date startTime = AttackReportCache.startTime;
            Date endTime = AttackReportCache.endTime;
            int longs = DateUtil.diffDate(11, startTime, endTime);
            int days = longs / 24;
            int hours = longs % 24;
            String longsStr = "";
            if (days > 0) {
                longsStr = days + "天";
            }

            if (hours > 0) {
                longsStr = longsStr + String.valueOf(hours) + "小时";
            }

            context.put("datetime", DateUtil.formatDateTime());
            context.put("attackCounts", intformat.format(attackCounts));
            context.put("ccCounts", ccCounts);
            context.put("uip", intformat.format(UIP));
            context.put("attackTypeSum", intformat.format(attackTypeSum));
            context.put("Visits", intformat.format(visits));
            context.put("fromDate", fromDate);
            context.put("attackDatajson", attackDatajson);
            context.put("allDaysDetailsjson", allDaysDetailsjson);
            context.put("attackVObjectjson", attackVObjectjson);
            context.put("attackCountryRegionList", attackCountryRegionList.size() > 200 ? attackCountryRegionList.subList(0, 200) : attackCountryRegionList);
            context.put("attackIPRegionList", attackIPRegionList.size() > 200 ? attackIPRegionList.subList(0, 200) : attackIPRegionList);
            context.put("ccIPRegionList", ccIPRegionList.size() > 200 ? ccIPRegionList.subList(0, 200) : ccIPRegionList);
            context.put("ccList", AttackReportCache.ccList.size() > 200 ? AttackReportCache.ccList.subList(0, 200) : AttackReportCache.ccList);
            context.put("attack_ip", intformat.format(AttackReportCache.attackIPList.size()));
            context.put("cc_ip", cc_ip);
            context.put("attackTypeMap", AttackReportCache.overviewMap);
            context.put("allAttackTypeList", AttackReportCache.allAttackTypelist);
            context.put("evt_hostSum", intformat.format(1L));
            context.put("evt_datePeriod", intformat.format(AttackReportCache.dataFrom.size()));
            if (AnalyzeSingle.useCC && AttackReportCache.ccCount.intValue() != 0) {
                context.put("evt_cc", AttackReportCache.getCcEvt(intformat));
                context.put("evt_allAttackSum", intformat.format((AttackReportCache.attackCount.intValue() + AttackReportCache.ccCount.intValue())));
            } else {
                context.put("evt_allAttackSum", intformat.format(AttackReportCache.attackCount.intValue()));
            }

            context.put("evt_attackLongs", longsStr);
            context.put("evt_attackEndTime", DateUtil.formatDateTime(endTime));
            context.put("evt_attack", AttackReportCache.getAttackEvt(intformat));
            PrintWriter pw = new PrintWriter(getReportattackFilePath(), "UTF-8");
            template.merge(context, pw);
            pw.close();
        } catch (ResourceNotFoundException var27) {
            var27.printStackTrace();
        } catch (ParseErrorException var28) {
            var28.printStackTrace();
        } catch (Exception var29) {
            var29.printStackTrace();
        }

    }

    public static void outputHtml() {
        try {
            Properties properties = new Properties();
            properties.setProperty("ISO-8859-1", "UTF-8");
            properties.setProperty("input.encoding", "UTF-8");
            properties.setProperty("output.encoding", "UTF-8");
            if (AnalyzeSingle.isJarExecute) {
                properties.setProperty("resource.loader", "jar");
                properties.setProperty("jar.resource.loader.class", "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
                properties.setProperty("jar.resource.loader.path", "jar:file:" + AnalyzeSingle.jarPath);
            } else {
                properties.setProperty("resource.loader", "class");
                properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
                properties.setProperty("class.resource.loader.path", AnalyzeSingle.basePath);
            }

            VelocityEngine velocityEngine = new VelocityEngine(properties);
            Template template = velocityEngine.getTemplate("template/blackReport.html", "UTF-8");
            VelocityContext context = new VelocityContext();
            NumberFormat performat = NumberFormat.getPercentInstance();
            performat.setMinimumFractionDigits(3);
            NumberFormat intformat = NumberFormat.getNumberInstance();
            intformat.setMaximumFractionDigits(0);
            NumberFormat decimalformat = NumberFormat.getNumberInstance();
            decimalformat.setRoundingMode(RoundingMode.HALF_UP);
            decimalformat.setMaximumFractionDigits(2);
            context.put("datetime", DateUtil.formatDateTime());
            int UV = RoutineReportCache.UVMap.size();
            long BAND = RoutineReportCache.totalband;
            int VISITS = RoutineReportCache.visits;
            int UIP = RoutineReportCache.ipStaMap.size();
            long LOGSIZE = RoutineReportCache.logSize;
            context.put("Visits", intformat.format((long)VISITS));
            context.put("PV", intformat.format((long)RoutineReportCache.PV));
            context.put("CUV", UV);
            if (UV > 0) {
                context.put("UV", intformat.format((long)UV));
            }

            context.put("UIP", intformat.format((long)UIP));
            if (BAND > 0L) {
                if (BAND <= 1048576L) {
                    context.put("Band", decimalformat.format((double)BAND / 1024.0) + " K");
                } else if (BAND >= 1073741824L) {
                    context.put("Band", decimalformat.format((double)BAND / 1024.0 / 1024.0 / 1024.0) + " G");
                } else {
                    context.put("Band", decimalformat.format((double)BAND / 1024.0 / 1024.0) + " M");
                }
            }

            context.put("Errors", intformat.format((long)(RoutineReportCache.stat4XXcount + RoutineReportCache.stat5XXcount)));
            if (LOGSIZE > 0L) {
                if (LOGSIZE <= 1048576L) {
                    context.put("LogSize", decimalformat.format((double)LOGSIZE / 1024.0) + " K");
                } else if (LOGSIZE >= 1073741824L) {
                    context.put("LogSize", decimalformat.format((double)LOGSIZE / 1024.0 / 1024.0 / 1024.0) + " G");
                } else {
                    context.put("LogSize", decimalformat.format((double)LOGSIZE / 1024.0 / 1024.0) + " M");
                }
            }

            List<StatBean> ipVisitsSortList = new ArrayList();
            Iterator iter = RoutineReportCache.ipStaMap.entrySet().iterator();

            while(iter.hasNext()) {
                Map.Entry<String, StatBean> entry = (Map.Entry)iter.next();
                StatBean iPStatBean = entry.getValue();
                if (iPStatBean.getBand() > 0L) {
                    if (iPStatBean.getBand() <= 1048576L) {
                        iPStatBean.setBandStr(decimalformat.format((double)iPStatBean.getBand() / 1024.0) + " K");
                    } else {
                        iPStatBean.setBandStr(decimalformat.format((double)iPStatBean.getBand() / 1024.0 / 1024.0) + " M");
                    }

                    iPStatBean.setBandRate(performat.format((double)iPStatBean.getBand() / (double)BAND));
                    if ((double)iPStatBean.getBand() / (double)BAND > 0.5) {
                        iPStatBean.setBandflag(1);
                    }
                }

                iPStatBean.setVisitStr(intformat.format(iPStatBean.getVisit()));
                iPStatBean.setVisitRate(performat.format((double)iPStatBean.getVisit() / (double)VISITS));
                if ((double)iPStatBean.getVisit() / (double)VISITS > 0.5) {
                    iPStatBean.setVisitflag(1);
                }

                iPStatBean.setCountry(Utils.getIPRegionLocal(iPStatBean.getIp()));
                ipVisitsSortList.add(entry.getValue());
            }

            Collections.sort(ipVisitsSortList, new StatBeanComparator());
            RoutineReportCache.ipStaMap.clear();
            if (ipVisitsSortList.size() > 200) {
                ipVisitsSortList = ((List)ipVisitsSortList).subList(0, 200);
            }

            context.put("ipVisitsSortList", ipVisitsSortList);
            List<StatBean> pageVisitsSortList = new ArrayList();
            iter = RoutineReportCache.pageVisitMap.entrySet().iterator();

            while(iter.hasNext()) {
                Map.Entry<String, StatBean> entry = (Map.Entry)iter.next();
                StatBean statBean = entry.getValue();
                bandCompute(statBean, performat, decimalformat, BAND, VISITS, intformat);
                (pageVisitsSortList).add(statBean);
            }

            Collections.sort(pageVisitsSortList, new StatBeanComparator());
            RoutineReportCache.pageVisitMap.clear();
            if (pageVisitsSortList.size() > 200) {
                pageVisitsSortList = ((List)pageVisitsSortList).subList(0, 200);
            }

            context.put("pageVisitsSortList", pageVisitsSortList);
            List<StatBean> staticPageVisitsSortList = new ArrayList();
            iter = RoutineReportCache.staticPageVisitMap.entrySet().iterator();

            while(iter.hasNext()) {
                Map.Entry<String, StatBean> entry = (Map.Entry)iter.next();
                StatBean statBean = entry.getValue();
                bandCompute(statBean, performat, decimalformat, BAND, VISITS, intformat);
                (staticPageVisitsSortList).add(statBean);
            }

            Collections.sort(staticPageVisitsSortList, new StatBeanComparator());
            RoutineReportCache.staticPageVisitMap.clear();
            if (staticPageVisitsSortList.size() > 200) {
                staticPageVisitsSortList = ((List)staticPageVisitsSortList).subList(0, 200);
            }

            context.put("staticPageVisitsSortList", staticPageVisitsSortList);
            List<StatBean> _404PageVisitsSortList = new ArrayList();
            iter = RoutineReportCache._404pageVisitMap.entrySet().iterator();

            while(iter.hasNext()) {
                Map.Entry<String, StatBean> entry = (Map.Entry)iter.next();
                StatBean statBean = entry.getValue();
                bandCompute(statBean, performat, decimalformat, BAND, VISITS, intformat);
                (_404PageVisitsSortList).add(statBean);
            }

            Collections.sort(_404PageVisitsSortList, new StatBeanComparator());
            RoutineReportCache._404pageVisitMap.clear();
            if (_404PageVisitsSortList.size() > 200) {
                _404PageVisitsSortList = ((List)_404PageVisitsSortList).subList(0, 200);
            }

            context.put("_404PageVisitsSortList", _404PageVisitsSortList);
            List<CommonStatBean> referersVisitsSortList = new ArrayList();

            iter = RoutineReportCache.refererMap.entrySet().iterator();
            while (iter.hasNext()){
                Map.Entry<String, Integer> entry = (Map.Entry)iter.next();
                CommonStatBean  statBean = new CommonStatBean();
                statBean.setKey(entry.getKey());
                statBean.setCount(entry.getValue());
                statBean.setRate(performat.format((double)entry.getValue() / (double)VISITS));
                statBean.setCountStr(intformat.format(statBean.getCount()));
                if ((double)statBean.getCount() / (double)VISITS > 0.5) {
                    statBean.setFlag(1);
                }
                referersVisitsSortList.add(statBean);
            }

            Collections.sort(referersVisitsSortList, new CommonStatBeanComparator());
            RoutineReportCache.refererMap.clear();
            if (referersVisitsSortList.size() > 200) {
                referersVisitsSortList = ((List)referersVisitsSortList).subList(0, 200);
            }

            context.put("referersVisitsSortList", referersVisitsSortList);
            List<StatBean> soVisitsSortList = new ArrayList();
            iter = RoutineReportCache.soVisitMap.entrySet().iterator();

            while(iter.hasNext()) {
                Map.Entry<String, StatBean> entry = (Map.Entry)iter.next();
                StatBean refStatBean = entry.getValue();
                bandCompute(refStatBean, performat, decimalformat, BAND, VISITS, intformat);
                (soVisitsSortList).add(refStatBean);
            }

            Collections.sort(soVisitsSortList, new StatBeanComparator());
            RoutineReportCache.soVisitMap.clear();
            if (soVisitsSortList.size() > 200) {
                soVisitsSortList = ((List)soVisitsSortList).subList(0, 200);
            }

            context.put("soVisitsSortList", soVisitsSortList);
            List<SearchKeyWordBean> keywordSortList = new ArrayList();
            iter = RoutineReportCache.keyWordsMap.entrySet().iterator();

            while(iter.hasNext()) {
                Map.Entry<String, SearchKeyWordBean> entry = (Map.Entry)iter.next();
                SearchKeyWordBean kwBean = entry.getValue();
                kwBean.setCountStr(intformat.format(kwBean.getCount()));
                (keywordSortList).add(kwBean);
            }

            Collections.sort(keywordSortList, new SearchKeyWordComparator());
            RoutineReportCache.keyWordsMap.clear();
            if (keywordSortList.size() > 10) {
                keywordSortList = ((List)keywordSortList).subList(0, 10);
            }

            context.put("keywordSortList", keywordSortList);
            List<CommonStatBean> regionVisitsSortList = new ArrayList();

            iter = RoutineReportCache.countryMap.entrySet().iterator();
            while (iter.hasNext()){
                Map.Entry<String, Integer> entry = (Map.Entry)iter.next();
                CommonStatBean regionVisitStatBean = new CommonStatBean();
                regionVisitStatBean.setKey(entry.getKey());
                regionVisitStatBean.setCount(entry.getValue());
                regionVisitStatBean.setRate(performat.format((double)entry.getValue() / (double)UV));
                regionVisitStatBean.setCountStr(intformat.format(regionVisitStatBean.getCount()));
                if ((double)regionVisitStatBean.getCount() / (double)UV > 0.5) {
                    regionVisitStatBean.setFlag(1);
                }
                regionVisitsSortList.add(regionVisitStatBean);
            }

            Collections.sort(regionVisitsSortList, new CommonStatBeanComparator());
            RoutineReportCache.countryMap.clear();
            if (regionVisitsSortList.size() > 200) {
                regionVisitsSortList = ((List)regionVisitsSortList).subList(0, 200);
            }

            context.put("regionVisitsSortList", regionVisitsSortList);
            List<CommonStatBean> pcOSVisitsSortList = new ArrayList();

            iter = RoutineReportCache.osMap.entrySet().iterator();
            while (iter.hasNext()){
                Map.Entry<String, Integer> entry = (Map.Entry)iter.next();
                CommonStatBean pcOsVisitStatBean = new CommonStatBean();
                pcOsVisitStatBean.setKey(entry.getKey());
                pcOsVisitStatBean.setCount(entry.getValue());
                pcOsVisitStatBean.setRate(performat.format((double)(Integer)entry.getValue() / (double)RoutineReportCache.osCount));
                pcOsVisitStatBean.setCountStr(intformat.format((long)pcOsVisitStatBean.getCount()));
                if ((double)pcOsVisitStatBean.getCount() / (double)UV > 0.5) {
                    pcOsVisitStatBean.setFlag(1);
                }
                pcOSVisitsSortList.add(pcOsVisitStatBean);
            }

            Collections.sort((List)pcOSVisitsSortList, new CommonStatBeanComparator());
            RoutineReportCache.osMap.clear();
            if (pcOSVisitsSortList.size() > 200) {
                pcOSVisitsSortList = ((List)pcOSVisitsSortList).subList(0, 200);
            }

            context.put("pcOSVisitsSortList", pcOSVisitsSortList);
            List<CommonStatBean> pcBrowserVisitsSortList = new ArrayList();

            iter = RoutineReportCache.browserMap.entrySet().iterator();
            while (iter.hasNext()){
                Map.Entry<String, Integer> entry = (Map.Entry)iter.next();
                CommonStatBean pcBrowserVisitStatBean = new CommonStatBean();
                pcBrowserVisitStatBean.setKey(entry.getKey());
                pcBrowserVisitStatBean.setCount(entry.getValue());
                pcBrowserVisitStatBean.setRate(performat.format((double)entry.getValue() / (double)RoutineReportCache.osCount));
                pcBrowserVisitStatBean.setCountStr(intformat.format(pcBrowserVisitStatBean.getCount()));
                if ((double)pcBrowserVisitStatBean.getCount() / (double)UV > 0.5) {
                    pcBrowserVisitStatBean.setFlag(1);
                }
                pcBrowserVisitsSortList.add(pcBrowserVisitStatBean);
            }


            Collections.sort(pcBrowserVisitsSortList, new CommonStatBeanComparator());
            RoutineReportCache.browserMap.clear();
            if (pcBrowserVisitsSortList.size() > 200) {
                pcBrowserVisitsSortList = ((List)pcBrowserVisitsSortList).subList(0, 200);
            }

            context.put("pcBrowserVisitsSortList", pcBrowserVisitsSortList);
            List<CommonStatBean> httpStatusSortList = new ArrayList();
            if (RoutineReportCache.stat2XXcount > 0) {
                CommonStatBean statBean = new CommonStatBean();
                statBean.setKey("2xx 成功");
                statBean.setCount(RoutineReportCache.stat2XXcount);
                statBean.setRate(performat.format((double)RoutineReportCache.stat2XXcount / (double)VISITS));
                statBean.setCountStr(intformat.format((long)statBean.getCount()));
                httpStatusSortList.add(statBean);
            }

            if (RoutineReportCache.stat3XXcount > 0) {
                CommonStatBean statBean = new CommonStatBean();
                statBean.setKey("3xx 重定向");
                statBean.setCount(RoutineReportCache.stat3XXcount);
                statBean.setRate(performat.format((double)RoutineReportCache.stat3XXcount / (double)VISITS));
                statBean.setCountStr(intformat.format((long)statBean.getCount()));
                httpStatusSortList.add(statBean);
            }

            if (RoutineReportCache.stat4XXcount > 0) {
                CommonStatBean statBean = new CommonStatBean();
                statBean.setKey("4xx 客户端请求错误");
                statBean.setCount(RoutineReportCache.stat4XXcount);
                statBean.setRate(performat.format((double)RoutineReportCache.stat4XXcount / (double)VISITS));
                statBean.setCountStr(intformat.format((long)statBean.getCount()));
                httpStatusSortList.add(statBean);
            }

            if (RoutineReportCache.stat5XXcount > 0) {
                CommonStatBean statBean = new CommonStatBean();
                statBean.setKey("5xx 服务器内部错误");
                statBean.setCount(RoutineReportCache.stat5XXcount);
                statBean.setRate(performat.format((double)RoutineReportCache.stat5XXcount / (double)VISITS));
                statBean.setCountStr(intformat.format((long)statBean.getCount()));
                httpStatusSortList.add(statBean);
            }

            Collections.sort(httpStatusSortList, new CommonStatBeanComparator());
            context.put("httpStatusSortList", httpStatusSortList);
            PrintWriter pw = new PrintWriter(getReportFilePath(), "UTF-8");
            template.merge(context, pw);
            pw.close();
        } catch (ResourceNotFoundException var27) {
            var27.printStackTrace();
        } catch (ParseErrorException var28) {
            var28.printStackTrace();
        } catch (Exception var29) {
            var29.printStackTrace();
        }

    }

    private static void bandCompute(StatBean statBean, NumberFormat performat, NumberFormat decimalformat, long BAND, int VISITS, NumberFormat intformat) {
        if (statBean.getBand() > 0L) {
            if (statBean.getBand() <= 1048576L) {
                statBean.setBandStr(decimalformat.format((double)statBean.getBand() / 1024.0) + " K");
            } else if (statBean.getBand() > 1073741824L) {
                statBean.setBandStr(decimalformat.format((double)statBean.getBand() / 1024.0 / 1024.0 / 1024.0) + " G");
            } else {
                statBean.setBandStr(decimalformat.format((double)statBean.getBand() / 1024.0 / 1024.0) + " M");
            }

            statBean.setBandRate(performat.format((double)statBean.getBand() / (double)BAND));
            if ((double)statBean.getBand() / (double)BAND > 0.5) {
                statBean.setBandflag(1);
            }
        }

        statBean.setVisitRate(performat.format((double)statBean.getVisit() / (double)VISITS));
        if ((double)statBean.getVisit() / (double)VISITS > 0.5) {
            statBean.setVisitflag(1);
        }

        statBean.setVisitStr(intformat.format((long)statBean.getVisit()));
    }

    public static void outputFile(List<AttackEntity> attackList, List<CCEntity> ccList) {
        File ccFile;
        BufferedWriter writer;
        Iterator i$;
        if (attackList.size() > 0) {
            ccFile = new File(getAttackFilePath());

            try {
                writer = new BufferedWriter(new FileWriter(ccFile));
                i$ = attackList.iterator();

                while(i$.hasNext()) {
                    AttackEntity entity = (AttackEntity)i$.next();
                    writer.write(entity.output());
                }

                writer.flush();
                writer.close();
            } catch (FileNotFoundException var8) {
                var8.printStackTrace();
            } catch (IOException var9) {
                var9.printStackTrace();
            }
        }

        if (ccList.size() > 0) {
            ccFile = new File(getCCFilePath());

            try {
                writer = new BufferedWriter(new FileWriter(ccFile));
                i$ = ccList.iterator();

                while(i$.hasNext()) {
                    CCEntity entity = (CCEntity)i$.next();
                    writer.write(entity.output());
                }

                writer.flush();
                writer.close();
            } catch (FileNotFoundException var6) {
                var6.printStackTrace();
            } catch (IOException var7) {
                var7.printStackTrace();
            }
        }

    }

    public static String getReportDir() {
        return AnalyzeSingle.basePath + File.separator + "result" + File.separator;
    }

    public static String getConfDir() {
        return AnalyzeSingle.basePath + File.separator + "conf" + File.separator;
    }

    public static void writeFile(String data) {
        if (file == null) {
            file = new File(getLongUrlFilePath());
        }

        try {
            FileUtils.write(file, data + "\r\n", "utf-8", true);
        } catch (IOException var2) {
            var2.printStackTrace();
        }

    }

    public static String getLongUrlFilePath() {
        return new String(getReportDir() + AnalyzeSingle.currentFile + "-" + AnalyzeSingle.currentTime + "-" + "可疑访问" + ".txt");
    }

    public static String getReportFilePath() {
        return new String(getReportDir() + AnalyzeSingle.currentFile + "-" + AnalyzeSingle.currentTime + "-" + "常规分析报告" + ".html");
    }

    public static String getReportattackFilePath() {
        return new String(getReportDir() + AnalyzeSingle.currentFile + "-" + AnalyzeSingle.currentTime + "-" + "安全分析报告" + ".html");
    }

    public static String getAttackFilePath() {
        return new String(getReportDir() + AnalyzeSingle.currentFile + "-" + AnalyzeSingle.currentTime + "-" + "漏洞攻击" + ".txt");
    }

    public static String getBasicStatFilePath() {
        return new String(getReportDir() + AnalyzeSingle.currentFile + "-" + AnalyzeSingle.currentTime + "-" + "日常统计" + ".txt");
    }

    public static String getRuleFilePath() {
        return new String(getConfDir() + "rules.ini");
    }

    public static String getCCFilePath() {
        return new String(getReportDir() + AnalyzeSingle.currentFile + "-" + AnalyzeSingle.currentTime + "-" + "CC攻击" + ".txt");
    }

    public static String getOverViewFilePath() {
        return new String(getReportDir() + AnalyzeSingle.currentFile + "-" + AnalyzeSingle.currentTime + "-" + "分析概览" + ".txt");
    }

    public static boolean updateRuleFile(String rules) {
        String newRulePath = getRuleFilePath() + "." + System.currentTimeMillis();
        File newRuleFile = new File(newRulePath);
        if (newRuleFile != null) {
            String[] array = rules.split("\t");
            String[] arr$ = array;
            int len$ = array.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                String s = arr$[i$];

                try {
                    FileUtils.write(newRuleFile, s + "\n", "utf-8", true);
                } catch (IOException var9) {
                    var9.printStackTrace();
                } catch (Exception var10) {
                    var10.printStackTrace();
                }
            }
        }

        File rule = new File(getRuleFilePath());
        if (newRuleFile != null && rule != null) {
            try {
                FileUtils.copyFile(newRuleFile, rule);
                newRuleFile.delete();
                return true;
            } catch (IOException var11) {
                var11.printStackTrace();
            }
        }

        return false;
    }

    public static void generateUid() {
        String configPath = AnalyzeSingle.basePath + File.separator + "conf" + File.separator + "config.ini";
        File configNew = new File(configPath);

        try {
            String s = Utils.getMac();
            if (s == null || s.length() != 17) {
                s = UUID.randomUUID().toString();
            }

            String sign = "sign:" + Base64.encodeBase64String(s.getBytes("utf-8"));
            FileUtils.write(configNew, sign + "\r\n", "utf-8", true);
        } catch (IOException var4) {
            var4.printStackTrace();
        } catch (Exception var5) {
            var5.printStackTrace();
        }

    }

    public static boolean updateRuleVersion(String newVersion) {
        String configPath = AnalyzeSingle.basePath + File.separator + "conf" + File.separator + "config.ini";
        File file = new File(configPath);
        List<String> lines = new ArrayList();
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
            String line = null;
            boolean updateRuleVer = false;

            while((line = reader.readLine()) != null) {
                if (!line.startsWith("rule_ver")) {
                    lines.add(line);
                } else {
                    lines.add("rule_ver:" + newVersion);
                    updateRuleVer = true;
                }
            }

            if (!updateRuleVer) {
                lines.add("rule_ver:" + newVersion);
            }

            reader.close();
        } catch (IOException var19) {
            var19.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException var16) {
                }
            }

        }

        File configNew = new File(configPath + ".new");

        try {
            Iterator i$ = lines.iterator();

            while(i$.hasNext()) {
                String s = (String)i$.next();
                FileUtils.write(configNew, s + "\r\n", "utf-8", true);
            }

            FileUtils.copyFile(configNew, file);
            configNew.delete();
            return true;
        } catch (IOException var17) {
            var17.printStackTrace();
        } catch (Exception var18) {
            var18.printStackTrace();
        }

        return false;
    }

    public static void main(String[] args) {
    }
}